package mo.tags.greedy;

import java.util.Arrays;

public class L621 {

    public int leastInterval(char[] tasks, int n) {
        int[] hash = new int[26];
        for (int i = 0; i < tasks.length; i++) {
            hash[tasks[i]-'A']++;
        }
        Arrays.sort(hash);
        int min = (n+1) * (hash[25] - 1) + 1;
        for (int i = 24; i >= 0; i--) {
            if (hash[i] == hash[25]) {
                min++;
            }
        }

        return Math.max(min, tasks.length);
    }

}
